*****************
* PRELIMINARIES *
*****************

* Filepaths
* ---------

global filepath = ""  //set your own working directotry here

global IN = "${filepath}replication files/"

global OUT = "${filepath}output/"  // make sure the output folder exists before running this code


*********************
* MAIN TEXT RESULTS *
*********************

* Table 1
* -------

use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if wave == 2019

gen inter_afr = AFR * suit
gen inter_asn = ASN * suit

estimates clear
eststo: reg dv AFR ASN suit inter_afr inter_asn, cluster(trialid) // main model from pre-registration plan
estadd local fes "No"
eststo: reg dv AFR ASN suit inter_afr inter_asn male ib3.agecat, cluster(trialid) // + covariates
estadd local fes "No"
eststo: reg dv suit inter_afr inter_asn i.actor, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: reg dv suit inter_afr inter_asn i.actor male ib3.agecat, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}Table_2019main_short.csv", replace ///
	b(%8.3f) se(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(AFR ASN suit inter_afr inter_asn _cons) ///
	order(AFR ASN suit inter_afr inter_asn _cons) ///
	coeflabels(AFR "Nigerian Confed." ASN "Chinese Confed." suit "Business Attire" inter_afr "Nigerian Confed. x Business Attire" inter_asn "Chinese Confed. x Business Attire"   _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	csv compress	



	
* Main Results Figures from Main Text
* ----------------------------------

use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"

// preliminaries
gen tx = 1 if wave == 2018
replace tx = 2 if AFR == 1 & suit == 0 & wave == 2018
replace tx = 3 if AFR == 1 & suit == 1 & wave == 2018

gen inter_afr = AFR * suit if wave == 2019
gen inter_asn = ASN * suit if wave == 2019


// defining matrices to graph
matrix define Fig1 = J(5, 3, 0)
matrix colnames Fig1 = "beta" "lo" "hi"

matrix define Fig2 = J(4, 3, 0)
matrix colnames Fig2 = "beta" "lo" "hi"


//take 2018 results from Table S4 Model 1
reg dv ib2.tx if wave == 2018, cluster(trialid) 
lincom _cons + 1.tx  // Italian Casual in 2018
matrix Fig1[1,1] = r(estimate)
matrix Fig1[1,2] = r(estimate) - 1.96 * r(se)
matrix Fig1[1,3] = r(estimate) + 1.96 * r(se)
lincom _cons         // Nigerian Casual in 2018
matrix Fig1[2,1] = r(estimate)
matrix Fig1[2,2] = r(estimate) - 1.96 * r(se)
matrix Fig1[2,3] = r(estimate) + 1.96 * r(se)
	
lincom 3.tx			// Effect of business attire for Nigerians in 2018
matrix Fig2[1,1] = r(estimate)
matrix Fig2[1,2] = r(estimate) - 1.96 * r(se)
matrix Fig2[1,3] = r(estimate) + 1.96 * r(se)
	

// take 2019 results from Table S5 Model 1
reg dv AFR ASN suit inter_afr inter_asn if wave == 2019, cluster(trialid)
lincom _cons         // Italian Casual in 2019
matrix Fig1[3,1] = r(estimate)
matrix Fig1[3,2] = r(estimate) - 1.96 * r(se)
matrix Fig1[3,3] = r(estimate) + 1.96 * r(se)
lincom _cons + AFR   // Nigerian Casual in 2019
matrix Fig1[4,1] = r(estimate)
matrix Fig1[4,2] = r(estimate) - 1.96 * r(se)
matrix Fig1[4,3] = r(estimate) + 1.96 * r(se)
lincom _cons + ASN   // Chinese Casual in 2019
matrix Fig1[5,1] = r(estimate)
matrix Fig1[5,2] = r(estimate) - 1.96 * r(se)
matrix Fig1[5,3] = r(estimate) + 1.96 * r(se)

lincom suit 		// Effect of business attire for Italians in 2019
matrix Fig2[4,1] = r(estimate)
matrix Fig2[4,2] = r(estimate) - 1.96 * r(se)
matrix Fig2[4,3] = r(estimate) + 1.96 * r(se)
lincom suit + inter_asn		// Effect of business attire for Chinese in 2019
matrix Fig2[3,1] = r(estimate)
matrix Fig2[3,2] = r(estimate) - 1.96 * r(se)
matrix Fig2[3,3] = r(estimate) + 1.96 * r(se)
lincom suit + inter_afr		// Effect of business attire for Nigerians in 2019
matrix Fig2[2,1] = r(estimate)
matrix Fig2[2,2] = r(estimate) - 1.96 * r(se)
matrix Fig2[2,3] = r(estimate) + 1.96 * r(se)


//graphing main results: comparison in casual dress
svmat Fig1, names(col)
gen N = _n in 1 / 2
replace N = _n + 0.5 in 3 / 5

twoway ///
	(bar beta N in 1, fcolor("65 106 153") lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar beta N in 2, fcolor("255 0 0") lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar beta N in 3, fcolor(white) lcolor("65 106 153") lwidth(medthick) barwidth(0.8)) ///
	(bar beta N in 4, fcolor(white) lcolor("255 0 0") lwidth(medthick) barwidth(0.8)) ///
	(bar beta N in 5, fcolor(white) lcolor("0 102 0") lwidth(medthick) barwidth(0.8)) ///
	(rcap hi lo N in 1, msize(0) lwidth(thick) lcolor(gs3)) ///
	(rcap hi lo N in 2, msize(0) lwidth(thick) lcolor(gs3)) ///
	(rcap hi lo N in 3, msize(0) lwidth(thick) lcolor("65 106 153")) ///
	(rcap hi lo N in 4, msize(0) lwidth(thick) lcolor("255 0 0")) ///
	(rcap hi lo N in 5, msize(0) lwidth(thick) lcolor("0 102 0")) ///
	, legend(ring(0) pos(1) order(3 "Italian" 4 "Nigerian" 5 "Chinese") row(1) size(medlarge)) ///
	ytitle("Proportion Sitting Next to Confederate" , box bexpand bcolor(gs7) color(white) size(large)) ///
	ylab(0(.1).45, grid) ///
	xtitle("") xlab(1.5 "2018 Round" 4.5 "2019 Round", labsize(medlarge)) scheme(lean1)
graph export "${OUT}MainFig1_color.eps", as(eps) replace


* graph in black and white for publication
twoway ///
	(bar beta N in 1, fcolor(gs3) lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar beta N in 2, fcolor(gs9) lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar beta N in 3, fcolor(gs3) lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar beta N in 4, fcolor(gs9) lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar beta N in 5, fcolor(gs15) lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(rcap hi lo N in 1, msize(0) lwidth(thick) lcolor(gs3)) ///
	(rcap hi lo N in 2, msize(0) lwidth(thick) lcolor(gs3)) ///
	(rcap hi lo N in 3, msize(0) lwidth(thick) lcolor(gs3)) ///
	(rcap hi lo N in 4, msize(0) lwidth(thick) lcolor(gs3)) ///
	(rcap hi lo N in 5, msize(0) lwidth(thick) lcolor(gs3)) ///
	, legend(ring(0) pos(1) order(3 "Italian" 4 "Nigerian" 5 "Chinese") row(1) size(medlarge)) ///
	ytitle("Proportion Sitting Next to Confederate" , box bexpand bcolor(gs3) color(white) size(large)) ///
	ylab(0(.1).45, grid) ///
	xtitle("") xlab(1.5 "2018 Round" 4.5 "2019 Round", labsize(medlarge)) scheme(lean1)
graph export "${OUT}MainFig1_bw.eps", as(eps) replace

drop beta hi lo N



// graphing main results: effect of the suit
svmat Fig2, names(col)
gen N = _n in 1 / 4
label define nlab 1 "Nigerian - 2018" 2 "Nigerian - 2019" 3 "Chinese - 2019" 4 "Italian - 2019", modify
label values N nlab
levelsof N if N == 4, local(blues)
levelsof N if N == 3, local(greens)
levelsof N if N == 2 | N == 1, local(reds)

twoway ///
	(rcap hi lo N in 4, horizontal msize(0) lcolor("65 106 153") lwidth(thick)) ///
	(rcap hi lo N in 3, horizontal msize(0) lcolor("0 102 0") lwidth(thick)) ///
	(rcap hi lo N in 2, horizontal msize(0) lcolor("255 0 0") lwidth(thick)) ///
	(rcap hi lo N in 1, horizontal msize(0) lcolor("255 0 0") lpattern(dash) lwidth(thick)) ///
	(scatter N beta in 4, msym(D) mcolor("65 106 153") msize(medlarge)) ///
	(scatter N beta in 3, msym(D) mcolor("0 102 0") msize(medlarge)) ///
	(scatter N beta in 1 / 2, msym(D) mcolor("255 0 0") msize(medlarge)) ///
	, xline(0, lpattern(dash) lcolor(gs6) ) ///
	xlab(, nogrid) ///
	yscale(range(0.5 4.5)) ///
	ytitle("") ///
	ylab(none, valuelabel) ///
	ylab(`blues', add custom labcolor("65 106 153") labsize(medlarge)) ///
	ylab(`greens', add custom labcolor("0 102 0") labsize(medlarge)) ///
	ylab(`reds', add custom labcolor("255 0 0") labsize(medlarge)) ///
	title("Effect of Business Attire on Sitting Rates", box bexpand bcolor(gs7) color(white) size(large)) ///
	legend(off) scheme(lean1)
graph export "${OUT}MainFig3_color.eps", as(eps) replace	
	
* graph in black and white for publication	
twoway ///
	(rcap hi lo N in 4, horizontal msize(0) lcolor(gs3) lwidth(thick)) ///
	(rcap hi lo N in 3, horizontal msize(0) lcolor(gs3) lwidth(thick)) ///
	(rcap hi lo N in 2, horizontal msize(0) lcolor(gs3) lwidth(thick)) ///
	(rcap hi lo N in 1, horizontal msize(0) lcolor(gs3) lpattern(dash) lwidth(thick)) ///
	(scatter N beta in 4, msym(D) mcolor(gs3) msize(medlarge)) ///
	(scatter N beta in 3, msym(D) mcolor(gs3) msize(medlarge)) ///
	(scatter N beta in 1 / 2, msym(D) mcolor(gs3) msize(medlarge)) ///
	, xline(0, lpattern(dash) lcolor(gs6) ) ///
	xlab(, nogrid) ///
	yscale(range(0.5 4.5)) ///
	ytitle("") ///
	ylab(, valuelabel labsize(medlarge)) ///
	title("Effect of Business Attire on Sitting Rates", box bexpand bcolor(gs3) color(white) size(large)) ///
	legend(off) scheme(lean1)
graph export "${OUT}MainFig3_bw.eps", as(eps) replace	
		

	
* Figure: Perceived Income
* -------------------------	
use "${IN}survey_data.dta", clear
keep if guess_income != .
keep if wave == 2019

gen AFR = 0
replace AFR = 1 if race == 2

gen ASN = 0
replace ASN = 1 if race == 3

gen interact_afr = AFR * suit
gen interact_asn = ASN * suit

xtset responseid
xtreg guess_income AFR ASN suit interact_afr interact_asn, fe

// graphing
matrix A = J(6,3,0)

lincom _cons //Italians, casual
matrix A[6,1] = `r(estimate)'
matrix A[6,2] = `r(estimate)' + 1.96*`r(se)'
matrix A[6,3] = `r(estimate)' - 1.96*`r(se)'

lincom _cons + suit //Italians, business
matrix A[5,1] = `r(estimate)'
matrix A[5,2] = `r(estimate)' + 1.96*`r(se)'
matrix A[5,3] = `r(estimate)' - 1.96*`r(se)'

lincom _cons + ASN //Chinese, casual
matrix A[4,1] = `r(estimate)'
matrix A[4,2] = `r(estimate)' + 1.96*`r(se)'
matrix A[4,3] = `r(estimate)' - 1.96*`r(se)'

lincom _cons + ASN + suit + interact_asn //Chinese, business
matrix A[3,1] = `r(estimate)'
matrix A[3,2] = `r(estimate)' + 1.96*`r(se)'
matrix A[3,3] = `r(estimate)' - 1.96*`r(se)'

lincom _cons + AFR //Nigerian, casual
matrix A[2,1] = `r(estimate)'
matrix A[2,2] = `r(estimate)' + 1.96*`r(se)'
matrix A[2,3] = `r(estimate)' - 1.96*`r(se)'

lincom _cons + AFR + suit + interact_afr //Nigerian, business
matrix A[1,1] = `r(estimate)'
matrix A[1,2] = `r(estimate)' + 1.96*`r(se)'
matrix A[1,3] = `r(estimate)' - 1.96*`r(se)'

cap drop A1 A2 A3
cap drop temp*
svmat A
gen tempx = _n if A1 != .
gen tempy = ceil(tempx/2)
gen tempsuit = mod(tempx, 2)
	
twoway ///
	(rcap A2 A3 tempy if tempy == 3, horizontal msize(vtiny) lwidth(thick) lcolor("65 106 153")) ///
	(rcap A2 A3 tempy if tempy == 2, horizontal msize(vtiny) lwidth(thick) lcolor("0 102 0")) ///
	(rcap A2 A3 tempy if tempy == 1, horizontal msize(vtiny) lwidth(thick) lcolor("255 0 0")) ///
	(scatter tempy A1 in 6, msym(O) msize(vlarge) mcolor("65 106 153")) ///
	(scatter tempy A1 in 5, msym(Oh) msize(vlarge) mcolor("65 106 153")) ///
	(scatter tempy A1 in 5, msym(O) msize(large) mcolor(white)) ///
	(scatter tempy A1 in 4, msym(O) msize(vlarge) mcolor("0 102 0")) ///
	(scatter tempy A1 in 3, msym(Oh) msize(vlarge) mcolor("0 102 0")) ///	
	(scatter tempy A1 in 3, msym(O) msize(large) mcolor(white)) ///
	(scatter tempy A1 in 2, msym(O) msize(vlarge) mcolor("255 0 0")) ///
	(scatter tempy A1 in 1, msym(Oh) msize(vlarge) mcolor("255 0 0")) ///
	(scatter tempy A1 in 1, msym(O) msize(large) mcolor(white)) ///
	, legend(ring(0) pos(1) order(4 "Casual" 5 "Business") row(1) size(medlarge)) ///
	text(1.02 1.7 "Nigerian", color(red) size(medlarge)) ///
	text(2.02 2.2 "Chinese", color("0 102 0") size(medlarge)) ///
	text(3.02 2.175 "Italian", color("65 106 153") size(medlarge)) ///
	yscale(off) ///
	yscale(range(0.6 3.6)) ///
	xlab(1 `" "EUR 500" "or less" "' 2 `" "EUR 501-" "EUR 1000" "' 3 `" "EUR 1001-" "EUR 1500" "' 4 `" "EUR 1501-" "EUR 2500" "' 5 `" "EUR 2501" "or more" "') ///
	xscale(range(0.75 5.25)) ///
	title("Estimated Monthly Income", box bexpand bcolor(gs7) color(white) size(large)) ///
	scheme(lean1)
graph export "${OUT}MainFig2_color.eps", as(eps) replace
	

twoway ///
	(rcap A2 A3 tempy if tempy == 3, horizontal msize(vtiny) lwidth(thick) lcolor(gs3)) ///
	(rcap A2 A3 tempy if tempy == 2, horizontal msize(vtiny) lwidth(thick) lcolor(gs3)) ///
	(rcap A2 A3 tempy if tempy == 1, horizontal msize(vtiny) lwidth(thick) lcolor(gs3)) ///
	(scatter tempy A1 in 6, msym(O) msize(vlarge) mcolor(gs3)) ///
	(scatter tempy A1 in 5, msym(Oh) msize(vlarge) mcolor(gs3)) ///
	(scatter tempy A1 in 5, msym(O) msize(large) mcolor(white)) ///
	(scatter tempy A1 in 4, msym(O) msize(vlarge) mcolor(gs3)) ///
	(scatter tempy A1 in 3, msym(Oh) msize(vlarge) mcolor(gs3)) ///	
	(scatter tempy A1 in 3, msym(O) msize(large) mcolor(white)) ///
	(scatter tempy A1 in 2, msym(O) msize(vlarge) mcolor(gs3)) ///
	(scatter tempy A1 in 1, msym(Oh) msize(vlarge) mcolor(gs3)) ///
	(scatter tempy A1 in 1, msym(O) msize(large) mcolor(white)) ///
	, legend(ring(0) pos(1) order(4 "Casual" 5 "Business") row(1) size(medlarge)) ///
	text(1.02 1.7 "Nigerian", color(gs3) size(medlarge)) ///
	text(2.02 2.2 "Chinese", color(gs3) size(medlarge)) ///
	text(3.02 2.175 "Italian", color(gs3) size(medlarge)) ///
	yscale(off) ///
	yscale(range(0.6 3.6)) ///
	xlab(1 `" "EUR 500" "or less" "' 2 `" "EUR 501-" "EUR 1000" "' 3 `" "EUR 1001-" "EUR 1500" "' 4 `" "EUR 1501-" "EUR 2500" "' 5 `" "EUR 2501" "or more" "') ///
	xscale(range(0.75 5.25)) ///
	title("Estimated Monthly Income", box bexpand bcolor(gs3) color(white) size(large)) ///
	scheme(lean1)
graph export "${OUT}MainFig2_bw.eps", as(eps) replace
	
	
	

*******************
* APPENDIX TABLES * 
*******************

* Descriptive Table Commuter Characteristics
* ------------------------------------------

use "${IN}exp_data.dta", clear
tab agecat, gen(dage)
tab ethnicity, gen(dethnic)
gen tempage = .
gen tempethnic = .


label var dv "Sit next to confederate"
label var male "Male"
label var tempage "Age Category:"
label var dage1 "\hspace{.2cm}18-25"
label var dage2 "\hspace{.2cm}26-35"
label var dage3 "\hspace{.2cm}36-45"
label var dage4 "\hspace{.2cm}46-55"
label var dage5 "\hspace{.2cm}56+"
label var tempethnic "Commuter judged to be:"
label var dethnic3 "\hspace{.2cm}Native Italian"
label var dethnic2 "\hspace{.2cm}Immigrant"
label var dethnic1 "\hspace{.2cm}Difficult to say"
label var dethnic4 "\hspace{.2cm}Tourist"


sutex dv male tempage dage1 dage2 dage3 dage4 dage5 tempethnic dethnic3 dethnic2 dethnic1 dethnic4 if wave == 2018, par label minmax nocheck  ///
	title("Summary Statistics of Commuters in 2018 and 2019") key(table:sumstat) 
	
sutex dv male tempage dage1 dage2 dage3 dage4 dage5 tempethnic dethnic3 dethnic2 dethnic1 dethnic4 if wave == 2019, par label minmax nocheck 

* Note: STATA output was copy/pasted into a formatted latex table



*  Balance Table: 2018
* -----------------------

use "${IN}exp_data.dta", clear
keep if wave == 2018
keep if ethnicity == "Italian"

tab agecat, gen(dage)


// IT vs AFR CASUAL
matrix A = J(6, 5, 0)
local i = 1
foreach var of varlist male dage1 dage2 dage3 dage4 dage5 {
	qui ttest `var' if suit == 0, by(AFR)

	matrix A[`i', 1] = r(mu_1)
	matrix A[`i', 2] = r(mu_2)
	
	qui tab `var' AFR if suit == 0, chi2
	matrix A[`i', 4] = r(p)
	
	local i = `i' + 1
}

// AFR Casual v Suit
local i = 1
foreach var of varlist male dage1 dage2 dage3 dage4 dage5 {
	qui ttest `var' if AFR == 1, by(suit)
	
	matrix A[`i', 3] = r(mu_2)
	
	qui tab `var' suit if AFR == 1, chi2
	matrix A[`i', 5] = r(p)
	
	local i = `i' + 1
}
matrix rownames A = "Male" "Age:18-25" "Age:26-35" "Age:36-45" "Age:46-55" "Age:56+"  
matrix colnames A = "Italian-Casual" "Nigerian-Causal" "Nigerian-Business" "(1)vs(2)" "(2)vs(3)"

outtable using "${OUT}STable_balance2018", mat(A) ///
	replace nobox center format(%9.3f) asis ///
	caption("Balance of Commuter Characteristics across Different Encounters in 2018") clabel("table:balance2018")




* Balance Table: 2019
* -----------------------

use "${IN}exp_data.dta", clear
keep if wave == 2019
keep if ethnicity == "Italian" 

tab agecat, gen(dage)

matrix A = J(18, 6, 0)

// Actor race effects, casual
local i = 1
foreach var of varlist male dage1 dage2 dage3 dage4 dage5 {
	qui ttest `var' if race != 2 & suit == 0, by(AFR)
	matrix A[`i', 1] = r(mu_1)
	matrix A[`i', 2] = r(mu_2)
	
	qui tab `var' AFR if race != 2 & suit == 0, chi2
	matrix A[`i', 4] = r(p)
	
	qui ttest `var' if race != 1 & suit == 0, by(ASN)
	matrix A[`i', 3] = r(mu_2)
	
	qui tab `var' ASN if race != 1 & suit == 0, chi2
	matrix A[`i', 5] = r(p)
	
	qui tab `var' ASN if race != 0 & suit == 0, chi2
	matrix A[`i', 6] = r(p)
	
	local i = `i' + 1
}

// Actor race effects, suit
local i = 7
foreach var of varlist male dage1 dage2 dage3 dage4 dage5 {
	qui ttest `var' if race != 2 & suit == 1, by(AFR)
	matrix A[`i', 1] = r(mu_1)
	matrix A[`i', 2] = r(mu_2)
	
	qui tab `var' AFR if race != 2 & suit == 1, chi2
	matrix A[`i', 4] = r(p)
	
	qui ttest `var' if race != 1 & suit == 1, by(ASN)
	matrix A[`i', 3] = r(mu_2)
	
	qui tab `var' ASN if race != 1 & suit == 1, chi2
	matrix A[`i', 5] = r(p)

	qui tab `var' ASN if race != 0 & suit == 1, chi2
	matrix A[`i', 6] = r(p)
	
	local i = `i' + 1
}


// treatment differences, by race
forvalues c = 1 / 3 {
	
	local i = 13
	
	local r = `c' - 1
	
	foreach var of varlist male dage1 dage2 dage3 dage4 dage5 {
		qui tab suit `var' if race == `r', chi2
		matrix A [`i', `c'] = r(p)
		
		local i = `i' + 1
	}
}
matrix colnames A = "Italian" "Nigerian" "Chinese" "(1)vs(2)" "(1)vs(3)" "(2)vs(3)"
matrix rownames A = "Male" "Age:18-25" "Age:26-35" "Age:36-45" "Age:46-55" "Age:56+" ///
	"Male" "Age:18-25" "Age:26-35" "Age:36-45" "Age:46-55" "Age:56+" ///
	"Male" "Age:18-25" "Age:26-35" "Age:36-45" "Age:46-55" "Age:56+"
	
outtable using "${OUT}STable_balance2019", mat(A) ///
	replace nobox center format(%9.3f) asis ///
	caption("Balance of Commuter Characteristics across Different Encounters in 2019") clabel("table:balance2019")



* Main Results 2018
* ---------------------

use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if wave == 2018

gen tx = 1
replace tx = 2 if AFR == 1 & suit == 0
replace tx = 3 if AFR == 1 & suit == 1

estimates clear
eststo: reg dv ib2.tx, cluster(trialid) // main model
estadd local fes "No"
eststo: reg dv ib2.tx male ib3.agecat, cluster(trialid) // + covariates
estadd local fes "No"
eststo: reg dv ib2.tx i.actor if tx != 1, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: reg dv ib2.tx i.actor male ib3.agecat if tx != 1, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}STable_2018main.tex", replace ///
	b(%8.3f) se(%8.3f) ar2(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(1.tx 2.tx 3.tx male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(1.tx 2.tx 3.tx male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(1.tx "Italian Confed. " 2.tx "Nigerian Confed. Casual" 3.tx "Nigerian Confed. Business" male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress


	
* Main Results 2019	
* ---------------------
	
use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if wave == 2019

gen inter_afr = AFR * suit
gen inter_asn = ASN * suit

estimates clear
eststo: reg dv AFR ASN suit inter_afr inter_asn, cluster(trialid) // main model from pre-registration plan
estadd local fes "No"
eststo: reg dv AFR ASN suit inter_afr inter_asn male ib3.agecat, cluster(trialid) // + covariates
estadd local fes "No"
eststo: reg dv suit inter_afr inter_asn i.actor, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: reg dv suit inter_afr inter_asn i.actor male ib3.agecat, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}STable_2019main.tex", replace ///
	b(%8.3f) se(%8.3f) ar2(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(AFR ASN suit inter_afr inter_asn male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(AFR ASN suit inter_afr inter_asn male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(AFR "Nigerian Confed." ASN "Chinese Confed." suit "Business Attire" inter_afr "Nigerian Confed. $\times$ Business Attire" inter_asn "Chinese Confed. $\times$ Business Attire"  male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	

	
// difference in sitting rates between Chinese and Nigerians reported in the main text:
use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if wave == 2019

gen inter_afr = AFR * suit
gen IT = race == 0
gen inter_IT = IT * suit

reg dv AFR IT suit inter_afr inter_IT, cluster(trialid)
* diff: -.0553984, p-value = 0.055



* Replication of 2018 Results Using Full Sample
* ----------------------------------------------
use "${IN}exp_data.dta", clear
keep if wave == 2018

gen tx = 1
replace tx = 2 if AFR == 1 & suit == 0
replace tx = 3 if AFR == 1 & suit == 1

estimates clear
eststo: reg dv ib2.tx, cluster(trialid) // main model
estadd local fes "No"
eststo: reg dv ib2.tx male ib3.agecat, cluster(trialid) // + covariates
estadd local fes "No"
eststo: reg dv ib2.tx i.actor if tx != 1, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: reg dv ib2.tx i.actor male ib3.agecat if tx != 1, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}STable_2018full.tex", replace ///
	b(%8.3f) se(%8.3f) ar2(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(1.tx 2.tx 3.tx male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(1.tx 2.tx 3.tx male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(1.tx "Italian Confed. " 2.tx "Nigerian Confed. Casual" 3.tx "Nigerian Confed. Business" male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress


	
* Replication of 2019 Results Using Full Sample
* ---------------------------------------------

use "${IN}exp_data.dta", clear
keep if wave == 2019

gen inter_afr = AFR * suit
gen inter_asn = ASN * suit

estimates clear
eststo: reg dv AFR ASN suit inter_afr inter_asn, cluster(trialid) // main model from pre-registration plan
estadd local fes "No"
eststo: reg dv AFR ASN suit inter_afr inter_asn male ib3.agecat, cluster(trialid) // + covariates
estadd local fes "No"
eststo: reg dv suit inter_afr inter_asn i.actor, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: reg dv suit inter_afr inter_asn i.actor male ib3.agecat, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}STable_2019full.tex", replace ///
	b(%8.3f) se(%8.3f) ar2(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(AFR ASN suit inter_afr inter_asn male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(AFR ASN suit inter_afr inter_asn male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(AFR "Nigerian Confed." ASN "Chinese Confed." suit "Business Attire" inter_afr "Nigerian Confed. $\times$ Business Attire" inter_asn "Chinese Confed. $\times$ Business Attire"  male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	


		
* Replication of 2018 Reults Using Logistic Regression
* -------------------------------------------------------

use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if wave == 2018

gen tx = 1
replace tx = 2 if AFR == 1 & suit == 0
replace tx = 3 if AFR == 1 & suit == 1

estimates clear
eststo: logit dv ib2.tx, cluster(trialid) // main model
estadd local fes "No"
eststo: logit dv ib2.tx male ib3.agecat, cluster(trialid) // + covariates
estadd local fes "No"
eststo: logit dv ib2.tx i.actor if tx != 1, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: logit dv ib2.tx i.actor male ib3.agecat if tx != 1, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}STable_2018logit.tex", replace ///
	b(%8.3f) se(%8.3f) pr2(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(1.tx 2.tx 3.tx male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(1.tx 2.tx 3.tx male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(1.tx "Italian Confed. " 2.tx "Nigerian Confed. Casual" 3.tx "Nigerian Confed. Business" male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress


* Replication of 2019 Results Using Logistic Regression
* --------------------------------------------------------
	
use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if wave == 2019

gen inter_afr = AFR * suit
gen inter_asn = ASN * suit

estimates clear
eststo: logit dv AFR ASN suit inter_afr inter_asn, cluster(trialid) // main model from pre-registration plan
estadd local fes "No"
eststo: logit dv AFR ASN suit inter_afr inter_asn male ib3.agecat, cluster(trialid) // + covariates
estadd local fes "No"
eststo: logit dv suit inter_afr inter_asn i.actor, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: logit dv suit inter_afr inter_asn i.actor male ib3.agecat, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}STable_2019logit.tex", replace ///
	b(%8.3f) se(%8.3f) pr2(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(AFR ASN suit inter_afr inter_asn male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(AFR ASN suit inter_afr inter_asn male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(AFR "Nigerian Confed." ASN "Chinese Confed." suit "Business Attire" inter_afr "Nigerian Confed. $\times$ Business Attire" inter_asn "Chinese Confed. $\times$ Business Attire"  male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	




* Robustness: 2018 Controlling for Number of Commuters already on the platform
* ----------------------------------------------------------------------------
	
use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if wave == 2018

gen numothers = numtarget - 1

gen tx = 1
replace tx = 2 if AFR == 1 & suit == 0
replace tx = 3 if AFR == 1 & suit == 1

estimates clear
eststo: reg dv ib2.tx numothers, cluster(trialid) // main model
estadd local fes "No"
eststo: reg dv ib2.tx male ib3.agecat numothers, cluster(trialid) // + covariates
estadd local fes "No"
eststo: reg dv ib2.tx i.actor numothers if tx != 1, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: reg dv ib2.tx i.actor male ib3.agecat numothers if tx != 1, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}STable_2018_numothers.tex", replace ///
	b(%8.3f) se(%8.3f) ar2(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(1.tx 2.tx 3.tx male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat numothers _cons) ///
	order(1.tx 2.tx 3.tx male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat numothers _cons) ///
	coeflabels(1.tx "Italian Confed. " 2.tx "Nigerian Confed. Casual" 3.tx "Nigerian Confed. Business" male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" numothers "Num. Other Commuters in Experimental Area" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress
	
	
	
	
* Robustness: 2019 Controlling for Num Targets
* -------------------------------------------------	
	
use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if wave == 2019

gen numothers = numtarget - 1

gen inter_afr = AFR * suit
gen inter_asn = ASN * suit

estimates clear
eststo: reg dv AFR ASN suit inter_afr inter_asn numothers, cluster(trialid) // main model from pre-registration plan
estadd local fes "No"
eststo: reg dv AFR ASN suit inter_afr inter_asn male ib3.agecat numothers, cluster(trialid) // + covariates
estadd local fes "No"
eststo: reg dv suit inter_afr inter_asn i.actor numothers, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: reg dv suit inter_afr inter_asn i.actor male ib3.agecat numothers, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}STable_2019_numothers.tex", replace ///
	b(%8.3f) se(%8.3f) ar2(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(AFR ASN suit inter_afr inter_asn male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat numothers _cons) ///
	order(AFR ASN suit inter_afr inter_asn male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat numothers _cons) ///
	coeflabels(AFR "Nigerian Confed." ASN "Chinese Confed." suit "Business Attire" inter_afr "Nigerian Confed. $\times$ Business Attire" inter_asn "Chinese Confed. $\times$ Business Attire"  male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" numothers "Num. Other Commuters in Experimental Area" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	

	
	
* Robustness: 2018 Dropping Young People
* -------------------------------------------------
	
use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if wave == 2018

drop if agecat == 1

gen tx = 1
replace tx = 2 if AFR == 1 & suit == 0
replace tx = 3 if AFR == 1 & suit == 1

estimates clear
eststo: reg dv ib2.tx, cluster(trialid) // main model
estadd local fes "No"
eststo: reg dv ib2.tx male ib3.agecat, cluster(trialid) // + covariates
estadd local fes "No"
eststo: reg dv ib2.tx i.actor if tx != 1, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: reg dv ib2.tx i.actor male ib3.agecat if tx != 1, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}STable_2018_noyoung.tex", replace ///
	b(%8.3f) se(%8.3f) ar2(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(1.tx 2.tx 3.tx male 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(1.tx 2.tx 3.tx male 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(1.tx "Italian Confed. " 2.tx "Nigerian Confed. Casual" 3.tx "Nigerian Confed. Business" male "Male Commuter"  2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+"  _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress

	

* Robustness: 2019 Dropping Young People
* --------------------------------------
	
use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if wave == 2019

drop if agecat == 1

gen inter_afr = AFR * suit
gen inter_asn = ASN * suit

estimates clear
eststo: reg dv AFR ASN suit inter_afr inter_asn, cluster(trialid) // main model from pre-registration plan
estadd local fes "No"
eststo: reg dv AFR ASN suit inter_afr inter_asn male ib3.agecat, cluster(trialid) // + covariates
estadd local fes "No"
eststo: reg dv suit inter_afr inter_asn i.actor, cluster(trialid) // actor FEs
estadd local fes "Yes"
eststo: reg dv suit inter_afr inter_asn i.actor male ib3.agecat, cluster(trialid) // actor FEs + covariates
estadd local fes "Yes"

esttab est* using "${OUT}STable_2019_noyoung.tex", replace ///
	b(%8.3f) se(%8.3f) ar2(%8.3f) ///
	scalars("fes Confed. Fixed Effects") ///
	keep(AFR ASN suit inter_afr inter_asn male 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(AFR ASN suit inter_afr inter_asn male 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(AFR "Nigerian Confed." ASN "Chinese Confed." suit "Business Attire" inter_afr "Nigerian Confed. $\times$ Business Attire" inter_asn "Chinese Confed. $\times$ Business Attire"  male "Male Commuter" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	
	
	
	
* Interactions with Commuters' Gender
* --------------------------------------- 
	
use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"	
keep if suit == 0

gen inter_afr = AFR * male
gen inter_asn = ASN * male
	
estimates clear
eststo: reg dv male AFR inter_afr if wave == 2018, cluster(trialid) // 2018, no age controls
eststo: reg dv male AFR inter_afr ib3.agecat if wave == 2018, cluster(trialid) // 2018 + age controls
eststo: reg dv male AFR inter_afr ASN inter_asn if wave == 2019, cluster(trialid) // 2019, no age controls
eststo: reg dv male AFR inter_afr ASN inter_asn ib3.agecat if wave == 2019, cluster(trialid) // 2019 + age controls

esttab est* using "${OUT}STable_gender_interact.tex", replace ///
	b(%8.3f) se(%8.3f) ar2(%8.3f) ///
	keep(AFR ASN male inter_afr inter_asn 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(AFR ASN male inter_afr inter_asn 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(AFR "Nigerian Confed." ASN "Chinese Confed." inter_afr "Nigerian Confed. $\times$ Male Commuter" inter_asn "Chinese Confed. $\times$ Male Commuter"  male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	
	

* Multi-level model pooling both waves
* ------------------------------------

use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"

gen inter_afr = AFR * suit
gen inter_asn = ASN * suit

estimates clear	
eststo: mixed dv AFR ASN suit inter_afr inter_asn i.wave || actor: suit inter_afr inter_asn 
eststo: mixed dv AFR ASN suit inter_afr inter_asn i.wave male ib3.agecat || actor: suit inter_afr inter_asn 

esttab est* using "${OUT}STable_multilevel.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	keep(AFR ASN suit inter_afr inter_asn 2019.wave male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(AFR ASN suit inter_afr inter_asn 2019.wave male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(AFR "Nigerian Confed." ASN "Chinese Confed." suit "Business Attire" inter_afr "Nigerian Confed. $\times$ Business Attire" inter_asn "Chinese Confed. $\times$ Business Attire" 2019.wave "2019 Wave" male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	

		
		
		
		
* Model w/o suit interactions
* ---------------------------

use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"		
		
estimates clear
eststo: reg dv AFR if wave == 2018, cluster(trialid) // 2018
eststo: reg dv AFR male ib3.agecat if wave == 2018, cluster(trialid) // 2018 + covariates
eststo: reg dv AFR ASN if wave == 2019, cluster(trialid) // 2019
eststo: reg dv AFR ASN male ib3.agecat if wave == 2019, cluster(trialid) // 2019 + covariates
eststo: reg dv AFR ASN, cluster(trialid) // both waves
eststo: reg dv AFR ASN male ib3.agecat, cluster(trialid) //  + covariates


esttab est* using "${OUT}STable_bigpool.tex", replace ///
	b(%8.3f) se(%8.3f) ar2(%8.3f) ///
	keep(AFR ASN male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(AFR ASN male 1.agecat 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(AFR "Nigerian Confed." ASN "Chinese Confed." male "Male Commuter" 1.agecat "Age: 18-25" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	
		
	
* Does Discrimination Disappear in the Suit Condition?: Anomaly
* ------------------------------------------------------------

use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if suit == 1

gen flag = 1 if actor == 7 & wave == 2019 & suit == 1 // flagging the outlier results

estimates clear	
eststo: reg dv AFR ASN, cluster(trialid)
eststo: reg dv AFR ASN male ib3.agecat, cluster(trialid)
eststo: reg dv AFR ASN if flag != 1, cluster(trialid)
eststo: reg dv AFR ASN male ib3.agecat if flag != 1, cluster(trialid)

esttab est* using "${OUT}STable_anomaly.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	keep(AFR ASN male 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	order(AFR ASN male 2.agecat 3.agecat 4.agecat 5.agecat _cons) ///
	coeflabels(AFR "Nigerian Confed." ASN "Chinese Confed." male "Male Commuter" 2.agecat "Age: 26-35" 3.agecat "Age: 36-45" 4.agecat "Age: 46-55" 5.agecat "Age: 56+"  _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	
		
		
* ------------------------------------------	
* Survey Respondents Descriptive Tables
* ------------------------------------------	

* Demographic Characteristics of Survey Respondents in 2018 and 2019: Table S18
* ------------------------------------------------------------------------------


use "${IN}survey_data.dta", clear

bysort responseid: gen temp = _n == 1
keep if temp

tab educ, gen(deduc)
tab employ, gen(demploy)
gen tempeduc = .
gen tempemploy = .

label var male "Male"
label var age "Age"
label var tempeduc "Highest Education Completed"
label var deduc1 "\hspace{.2cm}Primary"
label var deduc2 "\hspace{.2cm}Middle"
label var deduc3 "\hspace{.2cm}Secondary"
label var deduc4 "\hspace{.2cm}University or Higher"
label var tempemploy "Employment Status:"
label var demploy1 "\hspace{.2cm}Employed"
label var demploy2 "\hspace{.2cm}Unemployed"
label var demploy3 "\hspace{.2cm}Retired"
label var demploy4 "\hspace{.2cm}Student"
label var demploy5 "\hspace{.2cm}Homemaker"
label var demploy6 "\hspace{.2cm}Other"


sutex  male age tempeduc deduc1 deduc2 deduc3 deduc4 tempemploy demploy1 demploy2 demploy3 demploy4 demploy5 demploy6 if wave == 2018, par label minmax nocheck  ///
	title("Demographic Characteristics of Survey Respondents in 2018 and 2019") key(table:demo_survey) 

sutex  male age tempeduc deduc1 deduc2 deduc3 deduc4 tempemploy demploy1 demploy2 demploy3 demploy4 demploy5 demploy6 if wave == 2019, par label minmax nocheck 


* Note: STATA output was copy/pasted into a formatted latex table



* Displaying Table of Survey Weights: S8
* -----------------------------------------
use "${IN}survey_data.dta", clear

matrix define w = J(5, 4, 0)
matrix colnames w = "Women" "Men" "women" "Men"
matrix rownames w = "Age:18-25" "Age:26-35" "Age:36-45" "Age:46-55" "Age:56+"  


forvalues m = 0 / 1 {
	forvalues a = 1 /5 {
		qui su weight if male == `m' & agecat == `a' & wave == 2018
		
		local row = `a'
		local col = `m' + 1
		matrix w[`row',`col'] = r(mean)
	}
}

forvalues m = 0 / 1 {
	forvalues a = 1 /5 {
		qui su weight if male == `m' & agecat == `a' & wave == 2019
		
		local row = `a'
		local col = `m' + 3
		matrix w[`row',`col'] = r(mean)
	}
}

outtable using "${OUT}STable_survey_weights", mat(w) ///
	replace center nobox format(%9.3f) asis 

	
	

* Distribution of ratings across profiles: S9
* ----------------------------------------

* SES Perceptions of Confederates

use "${IN}survey_data.dta", clear
keep if guess_income != .

collapse (count) guess_income, by(confed suit)

reshape wide guess_income, i(confed) j(suit)
replace guess_income1 = 0 if guess_income1 == .
gen total = guess_income0 + guess_income1

set obs 12
replace confed = _n in 11 / 12
label define confedlab 11 "2018 Total" 12 "2019 Total", modify

rename guess_income0 casual
rename guess_income1 business

gen year = 2019
replace year = 2018 if confed == 1 | confed == 2 | confed == 5 | confed == 6 | confed == 11

gen row = . 
replace row = 1 if confed == 1
replace row = 2 if confed == 2
replace row = 3 if confed == 5
replace row = 4 if confed == 6
replace row = 5 if confed == 11
replace row = 6 if confed == 3
replace row = 7 if confed == 4
replace row = 8 if confed == 7
replace row = 9 if confed == 8
replace row = 10 if confed == 9
replace row = 11 if confed == 10
replace row = 12 if confed == 12

sort row

foreach var of varlist casual business total {
	replace `var' = `var'[1] + `var'[2] + `var'[3] + `var'[4]  if confed == 11
	replace `var' = `var'[6] + `var'[7] + `var'[8] + `var'[9] + `var'[10] + `var'[11] if confed == 12
}

list year confed casual business total

* NOTE: the STATA data was copy/pasted into Latex

	
* Income Question in 2019: Table S19
* ----------------------------------

use "${IN}survey_data.dta", clear
keep if guess_income != .
keep if wave == 2019

gen AFR = 0
replace AFR = 1 if race == 2

gen ASN = 0
replace ASN = 1 if race == 3

gen interact_afr = AFR * suit
gen interact_asn = ASN * suit

xtset responseid

estimates clear
qui eststo: xtreg guess_income AFR ASN suit interact_afr interact_asn, fe
estadd local weight "No"

qui eststo: xtreg guess_income AFR ASN suit interact_afr interact_asn [pweight = weight], fe
estadd local weight "Yes"

esttab est* using "${OUT}STable_2019incomeratings.tex", replace ///
	b(%8.3f) se(%8.3f) r2(%8.3f) ///
	scalars("weight Weights") ///
	keep(AFR ASN suit interact_afr interact_asn _cons) ///
	order(AFR ASN suit interact_afr interact_asn _cons ) ///
	coeflabels(AFR "Nigerian Profile" ASN "Chinese Profile" suit "Confederate in Business Attire" interact_afr "Nigerian Profile $\times$ Business Attire" interact_asn "Chinese Profile $\times$ Business Attire" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress
	
	
* Income Question in 2018: Table S20
* -----------------------------------

use "${IN}survey_data.dta", clear
keep if guess_income != .
keep if wave == 2018

bysort responseid: egen tempsuit = mean(suit)

gen AFR = 0
replace AFR = 1 if race == 2
gen interact_afr = AFR * suit


xtset responseid

estimates clear
qui eststo: xtreg guess_income AFR if tempsuit == 0, fe
estadd local weight "No"

qui eststo: xtreg guess_income AFR if tempsuit == 0 [pweight = weight], fe
estadd local weight "Yes"
	
qui eststo: reg guess_income suit if AFR == 1, robust
estadd local weight "No"	
	
qui eststo: reg guess_income suit if AFR == 1 [pweight = weight], robust
estadd local weight "Yes"

esttab est* using "${OUT}STable_2018incomeratings.tex", replace ///
	b(%8.3f) se(%8.3f) r2(%8.3f) ///
	scalars("weight Weights") ///
	keep(AFR suit _cons) ///
	order(AFR suit _cons ) ///
	coeflabels(AFR "Nigerian Profile" suit "Confederate in Business Attire" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress

	

* Survey results of attitudes: Table S21
* ---------------------------------------

use "${IN}survey_data.dta", clear

foreach var of varlist worried discrim {
	egen std`var' = std(`var')
}

estimates clear
eststo: qui reg stdworried ib3.race, robust
estadd local weight "No"

eststo: qui reg stdworried ib3.race [pweight = weight], robust
estadd local weight "Yes"

eststo: qui reg stddiscrim ib3.race, robust
estadd local weight "No"

eststo: qui reg stddiscrim ib3.race [pweight = weight], robust
estadd local weight "Yes"


//table
esttab est* using "${OUT}STable_attitudes.tex", replace ///
	b(%8.3f) se(%8.3f) r2(%8.3f) ///
	scalars("weight Weights") ///
	keep(2.race _cons) ///
	order(2.race _cons ) ///
	coeflabels(2.race "African Version of Survey" _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	mgroups("\underline{Worried about Immigration}" "\underline{Beliefs about Discrimination}" "\underline{Implicit Negative Associations}", ///
		pattern(1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat()) ///
	tex compress
	


	

********************	
* APPENDIX FIGURES *
********************
	
* S5/Figure S4: Sitting Rates for Confederates in Casual Dress: One at a Time
* ---------------------------------------------------------------------------

use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"
keep if suit == 0

gen confed = .
replace confed = 1 if actor == 5
replace confed = 2 if actor == 1
replace confed = 3 if actor == 6
replace confed = 4 if actor == 4
replace confed = 5 if actor == 2
replace confed = 6 if actor == 8
replace confed = 7 if actor == 10 
replace confed = 8 if actor == 3
replace confed = 9 if actor == 7 & wave == 2018 // same actor in 2019
replace confed = 10 if actor == 7 & wave == 2019 // same actor in 2018
replace confed = 11 if actor == 9

collapse dv, by(confed wave)
sort confed

label define confedlab 1 "IT 1" 2 "IT 2" 3 "IT 3" 4 "IT 4" ///
	5 "C 1" 6 "C 2" ///
	7 "N 1" 8 "N 2" 9 "N 3" 10 "N 3" 11 "N 4", modify
label values confed confedlab

twoway ///
	(bar dv confed in 1, fcolor("65 106 153") lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar dv confed in 2, fcolor("65 106 153") lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar dv confed in 3, fcolor(none) lcolor("65 106 153") lwidth(medthick) barwidth(0.8)) ///
	(bar dv confed in 4, fcolor(none) lcolor("65 106 153") lwidth(medthick) barwidth(0.8)) ///
	(bar dv confed in 5, fcolor(none) lcolor("0 102 0") lwidth(medthick) barwidth(0.8)) ///
	(bar dv confed in 6, fcolor(none) lcolor("0 102 0") lwidth(medthick) barwidth(0.8)) ///
	(bar dv confed in 7, fcolor("255 0 0") lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar dv confed in 8, fcolor("255 0 0") lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar dv confed in 9, fcolor("255 0 0") lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar dv confed in 10, fcolor(none) lcolor("255 0 0") lwidth(medthick) barwidth(0.8)) ///
	(bar dv confed in 11, fcolor(none) lcolor("255 0 0") lwidth(medthick) barwidth(0.8)) ///
	, legend(ring(0) pos(1) order(2 "2018" 3 "2019") row(1) size(medlarge)) ///
	ytitle("Proportion Sitting Next to Confederate" , box bexpand bcolor(gs7) color(white) size(large)) ///
	ylab(0(.1).45) ///
	xtitle("") ///
	xlab(1(1)11,valuelab)
graph export "${OUT}casual_results_actors.png", as(png) replace



* Effect of Suits for each individual actor: Figure S5
* ----------------------------------------------------

use "${IN}exp_data.dta", clear
keep if ethnicity == "Italian"

gen confed = .
replace confed = 9 if actor == 6 
replace confed = 8 if actor == 4 
replace confed = 7 if actor == 2
replace confed = 6 if actor == 8 
replace confed = 5 if actor == 10 
replace confed = 4 if actor == 3 
replace confed = 3 if actor == 7 & wave == 2018 // same actor in 2018
replace confed = 2 if actor == 7 & wave == 2019 // same actor in 2019
replace confed = 1 if actor == 9
label define confedlab 1 "Nigerian 4" 2 "Nigerian 3" 3 "Nigerian 3" 4 "Nigerian 2" 5 "Nigerian 1" 6 "Chinese 2" 7 "Chinese 1" 8 "Italian 4" 9 "Italian 3" , modify
label values confed confedlab
drop if confed == .

matrix define A = J(9, 3, 0)
matrix colnames A = "beta" "lo" "hi"

xtset confed

forvalues row = 1 / 9 {
	qui reg dv i.suit##ib`row'.confed male i.agecat, cluster(trialid)
	matrix B = r(table)
	
	matrix A[`row', 1] = B[1,2]
	matrix A[`row', 2] = B[5,2]
	matrix A[`row', 3] = B[6,2]
}

svmat A
keep A1 A2 A3
gen confed = _n
label values confed confedlab
drop if A1 == .

gen race = 1 if confed == 9 | confed == 8
replace race = 2 if confed == 7 | confed == 6
replace race = 3 if confed <= 5

levelsof confed if race == 1, local(blues)
levelsof confed if race == 2, local(greens)
levelsof confed if race == 3, local(reds)
twoway ///
	(rcap A2 A3 confed in 8 / 9, horizontal msize(0) lcolor("65 106 153") lwidth(thick)) ///
	(rcap A2 A3 confed in 6 / 7, horizontal msize(0) lcolor("0 102 0") lwidth(thick)) ///
	(rcap A2 A3 confed in 3 / 5, horizontal msize(0) lcolor("255 0 0") lpattern(dash) lwidth(thick)) ///
	(rcap A2 A3 confed in 1 / 2, horizontal msize(0) lcolor("255 0 0") lwidth(thick)) ///
	(scatter confed A1 in 8 / 9, msym(D) mcolor("65 106 153") msize(medlarge)) ///
	(scatter confed A1 in 6 / 7, msym(D) mcolor("0 102 0") msize(medlarge)) ///
	(scatter confed A1 in 1 / 5, msym(D) mcolor("255 0 0") msize(medlarge)) ///
	, xline(0, lpattern(dash) lcolor(gs6) ) ///
	xlab(, grid) ///
	yscale(range(0.5 9.5)) ///
	ytitle("") ///
	ylab(none, valuelabel) ///
	ylab(`blues', add custom labcolor("65 106 153") labsize(medlarge)) ///
	ylab(`greens', add custom labcolor("0 102 0") labsize(medlarge)) ///
	ylab(`reds', add custom labcolor("255 0 0") labsize(medlarge)) ///
	title("Effect of Business Attire on Sitting Rates", box bexpand bcolor(gs7) color(white) size(large)) ///
	legend(order(3 "2018 Trials" 4 "2019 Trials") ring(0) pos(1) col(1) size(medlarge)) ///
	scheme(lean1)
graph export "${OUT}suit_results_actors.png", as(png) replace

	
	

	
* Implicit bias against African and Asian faces: Figure S7
* ---------------------------------------------------------

use "${IN}survey_data.dta", clear

reg iat ib2.race, robust

matrix define IAT = J(2, 3, 0)
matrix colnames IAT = "beta" "lo" "hi"

qui lincom _cons  // bias against Africans 
matrix IAT[1,1] = `r(estimate)'
matrix IAT[1,2] = `r(estimate)' - 1.96 * `r(se)'
matrix IAT[1,3] = `r(estimate)' + 1.96 * `r(se)'
qui lincom _cons + 3.race // bias against asians
matrix IAT[2,1] = `r(estimate)'
matrix IAT[2,2] = `r(estimate)' - 1.96 * `r(se)'
matrix IAT[2,3] = `r(estimate)' + 1.96 * `r(se)'

// graphing
svmat IAT, names(col)
gen N = _n if beta != .

twoway ///
	(bar beta N in 1, fcolor("255 0 0") lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(bar beta N in 2, fcolor("0 102 0") lcolor(gs3) lwidth(medthick) barwidth(0.8)) ///
	(rcap hi lo N in 1, msize(0) lwidth(thick) lcolor(gs3)) ///
	(rcap hi lo N in 2, msize(0) lwidth(thick) lcolor(gs3)) ///
	, legend(ring(0) pos(1) order(1 "African" 2 "Asian") row(1) size(medlarge)) ///
	ytitle("Anti-Minority Bias (standardized d.score)" , box bexpand bcolor(gs7) color(white) size(medlarge)) ///
	ylab(0(.1).6) ///
	xtitle("") ///
	xscale(range(0.5 2.5)) xlab(none)
graph export "${OUT}Fig_IAT_New.png", as(png) replace	
		
